import { reqGetRoles } from "@/api/reqRole"
import type { ROLE } from "@/types/role"
import { defineStore } from "pinia"
import { onMounted, ref } from "vue"

export const useRoleStore = defineStore("role", () => {
  // 展示已有角色
  const roleList = ref<ROLE[]>([])
  // 获取已经存在的角色
  async function getRoles() {
    const { status, data } = await reqGetRoles()
    if (status === 0) {
      roleList.value = data
    }
  }
  // 页面挂载后获取所有角色
  onMounted(() => {
    getRoles()
  })
  return {
    roleList,
    getRoles,
  }
})
